﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AgileComponents.DataConnection.Sampes
{
    public partial class SamplesExplorer : Form
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SamplesExplorer"/> class.
        /// </summary>
        public SamplesExplorer()
        {
            InitializeComponent();
        }

        #endregion

        #region Private Fields

        private DataConnectionControl DataConnectionControl;

        #endregion

        #region Private Methods

        /// <summary>
        /// Loads the data connection control.
        /// </summary>
        /// <param name="control">The control.</param>
        private void LoadDataConnectionControl(DataConnectionControl control)
        {
            DataConnectionControl = control;
            this.SuspendLayout();
            this.databaseConfiguratorPanel.Controls.Clear();
            this.databaseConfiguratorPanel.Controls.Add(control);
            this.ResumeLayout();
        }

        #endregion

        #region Handlers

        /// <summary>
        /// Handles the CheckedChanged event of the sqlServerRadioButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void sqlServerRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.LoadDataConnectionControl(new SqlServerDataConnectionControl());
        }

        /// <summary>
        /// Handles the CheckedChanged event of the mySqlRadioButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void mySqlRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.LoadDataConnectionControl(new MySqlDataConnectionControl());
        }

        /// <summary>
        /// Handles the CheckedChanged event of the oracleRadioButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void oracleRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.LoadDataConnectionControl(new OracleDataConnectionControl());
        }

        /// <summary>
        /// Handles the Load event of the SamplsesExplorer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void SamplesExplorer_Load(object sender, EventArgs e)
        {
            this.sqlServerRadioButton.PerformClick();
        }

        /// <summary>
        /// Handles the Click event of the okButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void okButton_Click(object sender, EventArgs e)
        {
            if (DataConnectionControl != null)
                MessageBox.Show(DataConnectionControl.GetConnectionString());
        }

        /// <summary>
        /// Handles the Click event of the cancelButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        #endregion
    }
}
